package com.opages.mybatis.interceptor;

import com.opages.mybatis.business.Business;
import com.opages.mybatis.model.Card;
import org.apache.ibatis.executor.resultset.ResultSetHandler;
import org.apache.ibatis.plugin.*;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.Properties;
import java.util.Set;

/**
 * @author daizhong.liu
 * @create 2021-12-27 16:30
 **/
public class CustomInterceptor implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        System.err.println("进来..."+invocation.toString());
        return invocation.proceed();
    }

    @Override
    public Object plugin(Object target) {
//        return Plugin.wrap(target, this);

        Class<?> type = target.getClass();
            return Proxy.newProxyInstance(
                    type.getClassLoader(),
                    type.getInterfaces(),
                    new InvocationHandler() {
                        @Override
                        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                            System.err.println("执行代理");
                            return method.invoke(target,args);
                        }
                    });
    }

    @Override
    public void setProperties(Properties properties) {

    }
}
